package com.yungee.learn.logic;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yungee.learn.entity.TrainCourseMedia;
import com.yungee.learn.service.TrainCourseMediaService;
import com.yungee.model.PageData;
import com.yungee.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TrainCourseMediaLogic {
    @Autowired
    private TrainCourseMediaService trainCourseMediaService;

    /**
     *
     * @param page
     * @param size
     * @param mediaType
     * @return
     */
    @DS("edu")
    public PageData mediaPage(int page, int size, String mediaType) {
        Page<TrainCourseMedia> pageQuery = new Page<>(page,size);
        QueryWrapper<TrainCourseMedia> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(mediaType)){
            queryWrapper.eq("media_type", mediaType);
        }
        queryWrapper.orderByAsc("order_num");
        Page<TrainCourseMedia> uploadRecordPage = trainCourseMediaService.page(pageQuery, queryWrapper);
        long total = pageQuery.getTotal();
        List<TrainCourseMedia> records = uploadRecordPage.getRecords();
        PageData pageData = new PageData(total,records);
        return pageData;
    }
}
